package Multithreading.threadPool;

import javafx.concurrent.Worker;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadPoolDemo1 {

    public static void main(String[] args) {

        /**
         *  ExecutorService executorService = Executors.newFixedThreadPool(1);
         *
         *  不推荐这种，这种方式对 线程控制力度太低
         *  推荐手动创建
         */


        ThreadPoolExecutor executor = new ThreadPoolExecutor(
                2,
                4,
                10,
                TimeUnit.MILLISECONDS,
                new ArrayBlockingQueue<>(2),
                new ThreadFactory() {
                    @Override
                    public Thread newThread(Runnable r) {
                        Thread thread = new Thread(r);
                        thread.setName("abc-def-g");
                        return thread;
                    }
                },
                new ThreadPoolExecutor.AbortPolicy()
        );

        executor.execute(() -> {
            for (int i = 0; i < 10; i++) {
                System.out.println(i);
            }
        });

        executor.shutdownNow();

        //System.out.println(0b11111111111111111111111111111111);




        here:
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                if(j == 9){
                    break here;
                }
            }
        }
    }

}
